package com.gxg.controller;

import com.gxg.entities.StudentUser;
import com.gxg.entities.User;
import com.gxg.services.AdminService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AdminController
{
  @Value("教师")
  private String adminRole;
  @Autowired
  AdminService adminService;
  
  @PostMapping({"/get_student_user_list"})
  @ResponseBody
  public List<StudentUser> getMemberList(@RequestParam("teacherName") String teacherName, HttpServletRequest request)
  {
    HttpSession session = request.getSession();
    return this.adminService.getMemberListByTeachName(teacherName);
  }
  
  @PostMapping({"/delete_member"})
  @ResponseBody
  public String deleteMembet(@RequestParam("studentId") String studentId, HttpServletRequest request)
  {
    HttpSession session = request.getSession();
    User user = (User)session.getAttribute("user");
    if (this.adminRole.equals(user.getRole())) {
      return this.adminService.deleteMember(studentId);
    }
    return "error:权限不够";
  }
}
